import 'package:cbec_app/components/base/base_chekbox.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/order/after_goods_item.dart';
import 'package:cbec_app/components/popup/question_descript.dart';
import 'package:cbec_app/components/popup/refund_reason_popup.dart';
import 'package:cbec_app/pages/my/controller/after_pop_ctr.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class Huanhuo extends StatelessWidget {
  final AfterPopController afterPopCtr = Get.put(AfterPopController());


  Huanhuo({super.key});

  @override
  Widget build(BuildContext context) {
    return BasePage(
      title: "换货",
      iconType: IconType.back,
      children: [
        Container(
          decoration: border_radis(Colors.white),
          margin: EdgeInsets.fromLTRB(8.w, 4.w, 8.w, 10.w),
          padding: EdgeInsets.all(10.w),
          child: ListView.builder(
              itemCount: afterPopCtr.goodsList.length,
              shrinkWrap: true,
              itemBuilder: (context,index){
              return AfterGoodsItem(showCheckBox: false,item: afterPopCtr.goodsList[index]['item'],showAdd: false);
            }),
        ),
        Container(
          decoration: border_radis(Colors.white),
          margin: EdgeInsets.only(left: 8.w, right: 8.w),
          padding: EdgeInsets.only(left: 10.w, right: 10.w, top: 10.w),
          child: Column(
            children: [
              listItem(
                context,
                  "申请原因*",
                  Row(
                    children: [
                      Text("选择申请原因",
                          style: setTextStyle(
                              14, FontWeight.w300, Tools.fromHex("#999999"))),
                      Icon(Icons.chevron_right, color: Tools.fromHex("#999999"))
                    ],
                  ),
                  type: 1),
              listItem(
                context,
                  "问题描述与上传凭证",
                  Row(
                    children: [
                      Text("上传有助于处理问题",
                          style: setTextStyle(
                              14, FontWeight.w300, Tools.fromHex("#999999"))),
                      Icon(Icons.chevron_right, color: Tools.fromHex("#999999"))
                    ],
                  ),
                  type: 2),
              
            ],
          ),
        ),
        
        //按钮
        Positioned(
            key: GlobalKey(debugLabel: 'Positioned'),
            bottom: MediaQuery.of(context).padding.bottom,
            child: Container(
              color: Colors.white,
              padding: EdgeInsets.fromLTRB(18.w, 5.w, 18.w, 5.w),
              width: 375.w,
              child: solidButton("提交", () {
                Tools.showToast("敬请期待");
              }),
            ))
      ],
    );
  }

  Widget listItem(BuildContext context, String txt, Widget right,
      {bool? hasBorder = true, int? type = 0}) {
    return BaseInteractive(
      onClick: () {
        switch (type) {
          case 1:
            refundReasonPopup(context);
            break;
          case 2:
          questionDescriptPopup(context);
            break;
          default:
        }
      },
      childWidget: Container(
        decoration: hasBorder == true ? bottom_gary_border : null,
        padding: EdgeInsets.fromLTRB(0.w, 15.w, 0.w, 20.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(txt,
                style: setTextStyle(
                    14, FontWeight.w300, Tools.fromHex("#000000"))),
            right
          ],
        ),
      ),
    );
  }

  ///富文本描述
  Widget descriptTxt() {
    TextStyle maintxt =
        setTextStyle(12, FontWeight.w300, Tools.fromHex("#999999"));
    TextStyle pointTxt =
        setTextStyle(12, FontWeight.w300, Tools.fromHex("#F83F2D"));

    return Container(
        padding: EdgeInsets.only(left: 8.w, right: 8.w),
        child: RichText(
          text: TextSpan(
            text: '当前可用积分',
            style: maintxt,
            children: <TextSpan>[
              TextSpan(text: '100 ', style: pointTxt),
              TextSpan(text: '售后需扣除可用积分', style: maintxt),
              TextSpan(text: '120', style: pointTxt),
              TextSpan(text: '需要购买', style: maintxt),
              TextSpan(
                text: '20',
                style: pointTxt,
              ),
              TextSpan(text: '积分才可申请退款购买积分金额将直接扣减退款金额 ', style: maintxt),
            ],
          ),
        ));
  }
}
